﻿@using TestOnlineProject.Models.Entities
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    ViewBag.Title = "ImportResult";
    var totalPage = 0;
}
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home", new { }, new { }) / @Html.ActionLink("Users", "Index") / @Html.ActionLink("Import Users", "Import")
    / Import Result
</div>
<script>
    $(document).ready(function () {
        goToPage(1);
    });

    function goToPage(page) {
        $(".user").hide();
        $(".p" + page).show();
    }
</script>
<br />
<div class="main_nav">
    <span>
        <a href="@Url.Content("~/User/Import")">
            <img src="@Url.Content("~/Images/back button.png")"/>
        </a>
    </span>
</div>
<br />
<table class="table table-bordered">
    <tr>
        <td style="width: 15%; text-align: right">
            Imported
        </td>
        <td>
            @ViewBag.Success users
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            Error
        </td>
        <td>
            @ViewBag.Fail users
        </td>
    </tr>
</table>
<br />
<div id="list">
    <div style="min-height: 430px">
        <table class="table table-hover" style="table-layout: fixed">
            <tr>
                <th style="vertical-align: middle; width: 50px">
                    No.
                </th>
                <th style="vertical-align: middle; width: 50px" >
                    Row
                </th>
                <th style="vertical-align: middle">
                    Username
                </th>
                <th style="vertical-align: middle">
                    E-Mail
                </th>
                <th style="vertical-align: middle">
                    Full Name
                </th>
                <th style="vertical-align: middle; width: 50px">
                    Role
                </th>
                <th style="vertical-align: middle">
                    Error
                </th>
            </tr>
            @{
                if (ViewBag.ListUser != null)
                {
                    var users = (List<UserErrorModel>)ViewBag.ListUser;
                    var count = 0;
                    for (int i = 0; i < users.Count; i++)
                    {
                        if (!String.IsNullOrEmpty(users[i].Error))
                        {
                            if (count % 10 == 0)
                            {
                                if (count == 0 && totalPage == 0)
                                {
                                    totalPage = 1;
                                }
                                else if (count > 0 && count < users.Count)
                                {
                                    totalPage++;
                                }
                            }
                            var pageClass = "p" + totalPage;
                            count++;
                            <tr style="color: red" class="@pageClass user">
                                <td>
                                    <span style="word-wrap: break-word">@count</span>
                                </td>
                                <td>
                                    <span style="word-wrap: break-word">@(i + 1)</span>
                                </td>
                                <td style="width: 15%">
                                    <span style="word-wrap: break-word">@users[i].Username</span>
                                </td>
                                <td style="width: 20%">
                                    <span style="word-wrap: break-word">@users[i].Email</span>
                                </td>
                                <td style="width: 15%">
                                    <span style="word-wrap: break-word">@users[i].FullName</span>
                                </td>
                                <td>
                                    <span style="word-wrap: break-word">@users[i].Role</span>
                                </td>
                                <td style="width: 20%">
                                    @users[i].Error
                                </td>
                            </tr>
                        }
                    }
                    for (int i = 0; i < users.Count; i++)
                    {
                        if (String.IsNullOrEmpty(users[i].Error))
                        {
                            if (count % 10 == 0)
                            {
                                if (count == 0 && totalPage == 0)
                                {
                                    totalPage = 1;
                                }
                                else if (count > 0 && count < users.Count)
                                {
                                    totalPage++;
                                }
                            }
                            var pageClass = "p" + totalPage;
                            count++;
                            <tr class="@pageClass user">
                                <td>
                                    <span style="word-wrap: break-word">@count</span>
                                </td>
                                <td>
                                    <span style="word-wrap: break-word">@(i + 1)</span>
                                </td>
                                <td style="width: 15%">
                                    <span style="word-wrap: break-word">@users[i].Username</span>
                                </td>
                                <td style="width: 20%">
                                    <span style="word-wrap: break-word">@users[i].Email</span>
                                </td>
                                <td style="width: 15%">
                                    <span style="word-wrap: break-word">@users[i].FullName</span>
                                </td>
                                <td>
                                    @users[i].Role
                                </td>
                                <td style="width: 20%">
                                    <span style="word-wrap: break-word">@users[i].Error</span>
                                </td>
                            </tr>
                        }
                    }
                }
            }
        </table>
    </div>
    <div id="page-selection"></div>
    <script>
        $('#page-selection').bootpag({
            total: @totalPage,
            maxVisible: 5
        }).on("page", function(event, num) {
            goToPage(num);
            $("#page").html(num);
        });
    </script>
</div>